package com.atguigu.algorithm.lru;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author xr-8
 * @create 2021-01-28 21:50
 */
public class LRUCacheEasyDemo<K,V> extends LinkedHashMap<K,V> {

    private int capacity;
    public LRUCacheEasyDemo(int capacity){
        super(capacity,0.75F,true);
        this.capacity = capacity;
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
        return super.size() > capacity;
    }

    public static void main(String[] args) {
        LRUCacheEasyDemo<Integer, Integer> lRUCacheDemo = new LRUCacheEasyDemo<>(3);
        lRUCacheDemo.put(1,10);
        lRUCacheDemo.put(2,20);
        lRUCacheDemo.put(3,30);
        System.out.println(lRUCacheDemo.keySet());
        lRUCacheDemo.put(4,10);
        System.out.println(lRUCacheDemo.keySet());
        lRUCacheDemo.put(3,10);
        System.out.println(lRUCacheDemo.keySet());
        lRUCacheDemo.put(3,10);
        System.out.println(lRUCacheDemo.keySet());
        lRUCacheDemo.put(3,10);
        System.out.println(lRUCacheDemo.keySet());
        lRUCacheDemo.put(5,10);
        System.out.println(lRUCacheDemo.keySet());
    }
}